package com.zz.inventory.service.impl;

import java.util.List;

import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zz.inventory.mapper.ExperimentScenariosMapper;
import com.zz.inventory.domain.ExperimentScenarios;
import com.zz.inventory.service.IExperimentScenariosService;

/**
 * 实验场景库Service业务层处理
 * 
 * @author zz
 * @date 2025-07-08
 */
@Service
public class ExperimentScenariosServiceImpl implements IExperimentScenariosService 
{
    @Autowired
    private ExperimentScenariosMapper experimentScenariosMapper;


    @Override
    public int changeStatus(Long scenarioId, String status) {
        // 1. 校验场景是否存在
        ExperimentScenarios scenario = experimentScenariosMapper.selectExperimentScenariosByScenarioId(scenarioId);
        if (scenario == null) {
            throw new ServiceException("实验场景不存在");
        }

        // 2. 校验状态值是否合法
        if (!"已发布".equals(status) && !"草稿".equals(status) && !"已归档".equals(status)) {
            throw new ServiceException("状态值不合法");
        }

        // 3. 更新状态
        ExperimentScenarios updateObj = new ExperimentScenarios();
        updateObj.setScenarioId(scenarioId);
        updateObj.setStatus(status);

        return experimentScenariosMapper.updateExperimentScenarios(updateObj);
    }

    /**
     * 查询实验场景库
     * 
     * @param scenarioId 实验场景库主键
     * @return 实验场景库
     */
    @Override
    public ExperimentScenarios selectExperimentScenariosByScenarioId(Long scenarioId)
    {
        return experimentScenariosMapper.selectExperimentScenariosByScenarioId(scenarioId);
    }

    /**
     * 查询实验场景库列表
     * 
     * @param experimentScenarios 实验场景库
     * @return 实验场景库
     */
    @Override
    public List<ExperimentScenarios> selectExperimentScenariosList(ExperimentScenarios experimentScenarios)
    {
        return experimentScenariosMapper.selectExperimentScenariosList(experimentScenarios);
    }

    /**
     * 新增实验场景库
     * 
     * @param experimentScenarios 实验场景库
     * @return 结果
     */
    @Override
    public int insertExperimentScenarios(ExperimentScenarios experimentScenarios)
    {
        experimentScenarios.setCreateTime(DateUtils.getNowDate());
        return experimentScenariosMapper.insertExperimentScenarios(experimentScenarios);
    }

    /**
     * 修改实验场景库
     * 
     * @param experimentScenarios 实验场景库
     * @return 结果
     */
    @Override
    public int updateExperimentScenarios(ExperimentScenarios experimentScenarios)
    {
        return experimentScenariosMapper.updateExperimentScenarios(experimentScenarios);
    }

    /**
     * 批量删除实验场景库
     * 
     * @param scenarioIds 需要删除的实验场景库主键
     * @return 结果
     */
    @Override
    public int deleteExperimentScenariosByScenarioIds(Long[] scenarioIds)
    {
        return experimentScenariosMapper.deleteExperimentScenariosByScenarioIds(scenarioIds);
    }

    /**
     * 删除实验场景库信息
     * 
     * @param scenarioId 实验场景库主键
     * @return 结果
     */
    @Override
    public int deleteExperimentScenariosByScenarioId(Long scenarioId)
    {
        return experimentScenariosMapper.deleteExperimentScenariosByScenarioId(scenarioId);
    }
}
